﻿Imports System.Runtime.Serialization
Imports System.ComponentModel
Imports ATS.Business.Entities.EntityStateClass


<DataContract()> _
<Serializable()> _
Public Class admPasswordConfig
    Implements INotifyPropertyChanged

    Private _isDirty As Boolean
    Private _PWLength As Nullable(Of Integer)
    Private _PWExpiration As Nullable(Of Integer)
    Private _PWLockAccount As Nullable(Of Integer)
    Private _PWFormat1 As Nullable(Of Boolean)
    Private _PWFormat2 As Nullable(Of Boolean)
    Private _PWFormat3 As Nullable(Of Boolean)
    Private _PWDifferentFromID As Nullable(Of Boolean)



#Region "Primitive Properties"
    Public Sub New()
    End Sub

    <DataMember()>
    Public Overridable Property id As Integer

    <DataMember()>
    Public Property PWLength() As Nullable(Of Integer)
        Get
            Return _PWLength
        End Get

        Set(ByVal value As Nullable(Of Integer))
            If Not value Is Nothing Then
                If value <> _PWLength Then
                    Me.DataStateChanged( _
                    EntityStateEnum.Modified, _
                    "PWLength")
                End If
            Else
                Throw New Exception("Please provide value for Password Length.")
            End If
            _PWLength = value
            OnPropertyChanged("PWLength")
        End Set
    End Property

    <DataMember()>
    Public Property PWExpiration() As Nullable(Of Integer)
        Get
            Return _PWExpiration
        End Get

        Set(ByVal value As Nullable(Of Integer))
            If Not value Is Nothing Then
                If value <> _PWExpiration Then
                    Me.DataStateChanged( _
                    EntityStateEnum.Modified, _
                    "PWExpiration")
                End If
            Else

                Throw New Exception("Please provide value for Password Expiration days.")
            End If
            _PWExpiration = value
            OnPropertyChanged("PWExpiration")
        End Set
    End Property

    <DataMember()>
    Public Property PWLockAccount() As Nullable(Of Integer)
        Get
            Return _PWLockAccount
        End Get

        Set(ByVal value As Nullable(Of Integer))
            If Not value Is Nothing Then
                If value <> _PWLockAccount Then
                    Me.DataStateChanged( _
                    EntityStateEnum.Modified, _
                    "PWLockAccount")
                End If
            Else
                Throw New Exception("Please provide value for Password Lock tries.")
            End If
            _PWLockAccount = value
            OnPropertyChanged("PWLockAccount")
        End Set
    End Property

    <DataMember()>
    Public Property PWFormat1() As Nullable(Of Boolean)
        Get
            Return _PWFormat1
        End Get

        Set(ByVal value As Nullable(Of Boolean))

            If value <> _PWFormat1 Then
                Me.DataStateChanged( _
                EntityStateEnum.Modified, _
                "PWFormat1")
            End If

            _PWFormat1 = value
            OnPropertyChanged("PWFormat1")
        End Set
    End Property

    <DataMember()>
    Public Property PWFormat2() As Nullable(Of Boolean)
        Get
            Return _PWFormat2
        End Get

        Set(ByVal value As Nullable(Of Boolean))

            If value <> _PWFormat2 Then
                Me.DataStateChanged( _
                EntityStateEnum.Modified, _
                "PWFormat2")
            End If

            _PWFormat2 = value
            OnPropertyChanged("PWFormat2")
        End Set
    End Property

    <DataMember()>
    Public Property PWFormat3() As Nullable(Of Boolean)
        Get
            Return _PWFormat3
        End Get

        Set(ByVal value As Nullable(Of Boolean))

            If value <> _PWFormat3 Then
                Me.DataStateChanged( _
                EntityStateEnum.Modified, _
                "PWFormat3")
            End If

            _PWFormat3 = value
            OnPropertyChanged("PWFormat3")
        End Set
    End Property

    <DataMember()>
    Public Property PWDifferentFromID() As Nullable(Of Boolean)
        Get
            Return _PWDifferentFromID
        End Get

        Set(ByVal value As Nullable(Of Boolean))

            If value <> _PWDifferentFromID Then
                Me.DataStateChanged( _
                EntityStateEnum.Modified, _
                "PWDifferentFromID")
            End If

            _PWDifferentFromID = value
            OnPropertyChanged("PWDifferentFromID")
        End Set
    End Property


    Public ReadOnly Property IsDirty() As Boolean
        Get
            Return Me.EntityState <> EntityStateEnum.Unchanged
        End Get
    End Property


    Public Sub ResetDirtyBit()
        Me.EntityState = EntityStateEnum.Unchanged
    End Sub

    Public Sub OnPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
#End Region


#Region "Support Procedures"
    Private _EntityState As EntityStateEnum
    Public Property EntityState() As EntityStateEnum
        Get
            Return _EntityState
        End Get
        Private Set(ByVal value As EntityStateEnum)
            _EntityState = value
        End Set
    End Property

    Private Sub DataStateChanged(ByVal dataState As  _
    EntityStateEnum, ByVal propertyName As String)
        ' Raise the event
        If Not String.IsNullOrEmpty(propertyName) Then
            RaiseEvent PropertyChanged(Me, _
            New PropertyChangedEventArgs(propertyName))
        End If

        ' If the state is deleted, mark it as deleted
        If dataState = EntityStateEnum.Deleted Then
            Me.EntityState = dataState
        End If

        If Me.EntityState = _
                       EntityStateEnum.Unchanged Then
            Me.EntityState = dataState
        End If
    End Sub


#End Region
End Class


